<?php
class MeetsStaffsController extends AppController {

	var $name = 'MeetsStaffs';        
        var $helpers = array('Html', 'Form', 'Ajax', 'Javascript');
        var $components = array('RequestHandler');
	function index() {
		$this->MeetsStaff->recursive = 0;
		$this->set('meetsStaffs', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid meets staff', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('meetsStaff', $this->MeetsStaff->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->MeetsStaff->create();
			if ($this->MeetsStaff->saveAll($this->data)) {
				$this->Session->setFlash(__('The meets staff has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The meets staff could not be saved. Please, try again.', true));
			}
		}
		$meets = $this->MeetsStaff->Meet->find('list',array('fields'=>'Meet.meet_name'));
                $departments = $this->MeetsStaff->Staff->Department->find('list',array('fields'=>'Department.department_name'));
		//$staffs = $this->MeetsStaff->Staff->find('list',array('fields'=>array('Staff.staff_name')));
                $staffs = array();
		$this->set(compact('meets', 'staffs','departments'));
	}
        
        function  getStaffs(){
         $this->set('options',
			$this->MeetsStaff->Staff->find('list',
				array(
					'conditions' => array(
						'Staff.department_id' => $this->data['MeetsStaff']['department_id']
					),
					'fields' => array('Staff.staff_name')
				)
			)
		);         
		$this->render('/meets_staffs/ajax_dropdown');
        }

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid meets staff', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->MeetsStaff->save($this->data)) {
				$this->Session->setFlash(__('The meets staff has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The meets staff could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->MeetsStaff->read(null, $id);
		}
		$meets = $this->MeetsStaff->Meet->find('list');
		$staffs = $this->MeetsStaff->Staff->find('list');
		$this->set(compact('meets', 'staffs'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for meets staff', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->MeetsStaff->delete($id)) {
			$this->Session->setFlash(__('Meets staff deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Meets staff was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
